package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.EmpMapper;
import cn.tedu.egmvc2.pojo.dto.AddEmpDto;
import cn.tedu.egmvc2.pojo.entity.Emp;
import cn.tedu.egmvc2.pojo.vo.EmpLisetVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/emp/")
public class EmpController {
    @Autowired
    private EmpMapper empMapper;

    @RequestMapping(value = "insert")
    public String addEmp(AddEmpDto addEmpDto){
        Emp emp=new Emp();
        BeanUtils.copyProperties(addEmpDto,emp);
        empMapper.insertEmp(emp);

        return "添加成功";
    }
    @RequestMapping(value = "select")
    public List<EmpLisetVO>empLiset(){
        System.out.println(empMapper.selectempLiset());
        return empMapper.selectempLiset();
    }
    @RequestMapping(value = "update")
    public String update(Emp emp){
        empMapper.updateEmp(emp);
        return "修改成功";
    }

    @RequestMapping(value = "delete")
    public String deleteEmp(int id){
        empMapper.deleteEmp(id);
        return "删除成功";
    }
}
